﻿package 第八章作业;

import java.util.Arrays;

public class 数组作业4 {
    public static void main(String[] args) {
       /* 4)、现在有如下一个数组： 
        int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5}; 
        要求将以上数组中的0项去掉，将不为0的值存入一个新的数组，
        生成新的数组为 
        int newArr[]={1,3,4,5,6,6,5,4,7,6,7,5};*/
        int oldArr[] = {1, 3, 4, 5, 0, 0, 6, 6, 0, 5, 4, 7, 6, 7, 0, 5};
        int b = 0;
        int newArr[] = {oldArr.length};
        for (int i = 0; i < oldArr.length; i++) {

            for (int j = i + 1; j < oldArr.length; j++) {
                if (oldArr[i] != 0) {
                    newArr[b] = oldArr[i];
                    b++;
                }

            }
            int tempArr[] = new int[b];
            System.arraycopy(newArr, 0, newArr, 0, b);
            System.out.println(Arrays.toString(newArr));

        }
    }
}